<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'loginBak.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet"
			href="skins/javascript/extjs/resources/css/ext-all.css"
			type="text/css" />
		<script type="text/javascript"
			src="skins/javascript/extjs/adapter/ext/ext-base.js">
</script>
		<script type="text/javascript" src="skins/javascript/extjs/ext-all.js">
</script>
		<script type="text/javascript">

function LoginForm() {

	var leftPanel = new Ext.Panel(
			{
				id : "leftPanel",
				bodyStyle : "padding:20px;background-color:Red;background-image: url(skins/images/loginbg.gif);",
				height : 98
			});

	var rightPanel = new Ext.Panel( {
		id : "rightPanel",
		labelPad : 0,
		labelWidth : 60,
		bodyStyle : "padding-left:120px;padding-top:30px",
		layout : "form",
		items : [ {
			xtype : "field",
			id : "userName",
			fieldLabel : "用户名",
			width : 150,
			emptyText : "用户名"
		}, {
			xtype : "field",
			id : "password",
			fieldLabel : "密&nbsp;&nbsp;&nbsp;码",
			inputType : "password",
			iconCls : "password",
			emptyText : "密码",
			width : 150
		} ],
		buttons : [ {
			xtype : "button",
			text : "确定",
			pressed : true,
			handler : validatorData
		}, /*pressed表示按钮是否按下，默认为false*/
		{
			xtype : "button",
			text : "取消",
			handler : function() {
				loginWindow.close();
			}
		} /*点击取消关闭Window,也可以调用loginWindow.hide()隐藏这个Window*/
		],
		buttonAlign : "center"
	});

	var loginPanel = new Ext.form.FormPanel( {
		id : "loginPanel",
		height : 300,
		frame : true,
		layout : "column",
		items : [ leftPanel, rightPanel ]
	});
	var loginWindow;
	if (!loginWindow) {
		loginWindow = new Ext.Window( {
			id : "loginWindow",
			title : "管理系统---登陆窗口",
			width : 500,//230, //Window宽度
			height : 300,//137, //Window高度
			resizable : false, /*是否可手动调整Window大小，默认为true*/
			closable : true, //关闭按钮，默认为true
			items : [ leftPanel, loginPanel ]
		});
	}

	loginWindow.show();
	//按回车时调用确定事件
	var map = new Ext.KeyMap(loginWindow.getEl(), {
		key : 13, //回车的键盘key值
		fn : validatorData
	});
	//确定事件
	function validatorData() {
		var userName = Ext.getCmp("userName").getValue();
		var Password = Ext.getCmp("password").getValue();
		if (Ext.util.Format.trim(userName) == ""
				|| Ext.util.Format.trim(Password) == "") {
			Ext.Msg.alert("警告", "请正确输入数据，用户名和密码都不能够为空！");
			return false;
		}
		//数据库连接及处理
		Ext.Ajax.request( {
			url : "./member/login.action",
			mothed : "POST",
			params : {
				username : Ext.get('username').getValue(),
				psw : Ext.get('password').getValue()
			},
			waitTitle : '登录信息中',
			waitMsg : '系统正在验证您的登录信息,请稍候...',
			success : function(resp, opts) {
				var respText = Ext.util.JSON.decode(resp.responseText);
				if (respText.success == "true") {
					location.href = "index.jsp";
				} else {
					Ext.MessageBox.alert('Wrong', respText.info);
				}
			},
			failure : function(resp, opts) {
				var respText = Ext.util.JSON.decode(resp.responseText);
				Ext.MessageBox.alert('Error', respText.info);
			}
		});
	}
}
Ext.onReady(LoginForm);
</script>
	</head>

	<body>
	</body>
</html>
